import threading
import time  # 导入 time 库
import os  # 导入 os 库

from package.Utils.log import logger,mylog  # 导入 logger 对象(python代码)
from package.Utils.Screen import screen,hotkey   # 导入 screen 对象(python代码)


# Ghost窗口任务运行
class MyGhostWindowTask:
    def __init__(self):
        pass
    def run(self):
        # if mylog.log_enabled is True:
        #     logger.info("运行")
        pass
myghostwintask = MyGhostWindowTask()

class MyGhostWindowThread():
    def __init__(self,parent=None):
        self.thread = threading.Thread(target=self.run, args=())  # 创建线程
        self.event = threading.Event()
        # self.thread.start()  # 启动线程
        if mylog.log_enabled is True:
            logger.info('线程创建成功')

    def run(self):
        from package.Utils.MainWindow import mywinutils  # 导入 mywinutils 对象(python代码)
        while True:
            while mywinutils.isrun is True:
                myghostwintask.run()
                if mywinutils.isrun is False:
                    self.Stop()
            time.sleep(0.01)

    def Start(self):
        if mylog.log_enabled is True:
            logger.info("Ghost Window Task Start")
        # 启动键盘监听器
        hotkey.start()
        # self.event.set()

    def Stop(self):
        if mylog.log_enabled is True:
            logger.info("Ghost Window Task Stop")
        hotkey.stop()
        # self.event.wait()

myghostwinthread = MyGhostWindowThread()
